package com.chartboost.sdk.impl;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Rect;
import android.os.Build;
import android.os.Build.VERSION;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import com.chartboost.sdk.Chartboost;
import com.chartboost.sdk.Libraries.b;
import com.chartboost.sdk.Libraries.d;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;

public class k
{
  public String a;
  public String b;
  public String c;
  public Map<String, String> d;
  public JSONObject e;
  public Map<String, String> f;
  public List<String> g;
  public a h;
  public boolean i;
  public JSONObject j = null;

  public k(String paramString1, String paramString2)
  {
    this.a = paramString1;
    this.b = paramString2;
    this.c = "GET";
  }

  public static k a(JSONObject paramJSONObject)
  {
    try
    {
      k localk = new k(paramJSONObject.getString("controller"), paramJSONObject.getString("action"));
      localk.g = d.a(paramJSONObject.optJSONArray("params"));
      localk.f = d.a(paramJSONObject.optJSONObject("query"));
      localk.e = paramJSONObject.optJSONObject("body");
      localk.i = paramJSONObject.getBoolean("ensureDelivery");
      localk.d = d.a(paramJSONObject.optJSONObject("headers"));
      return localk;
    }
    catch (Exception localException)
    {
      Log.w("Chartboost", "Unable to deserialize failed request");
    }
    return null;
  }

  private void b(Context paramContext)
  {
    try
    {
      if ((paramContext instanceof Activity))
      {
        Activity localActivity = (Activity)paramContext;
        localRect = new Rect();
        localActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect);
        if (Build.VERSION.SDK_INT < 9)
          localRect.top = 0;
        int i1 = localRect.width();
        m = i1;
      }
    }
    catch (Exception localException1)
    {
      while (true)
      {
        try
        {
          Rect localRect;
          int i2 = localRect.height();
          n = i2;
          Display localDisplay = ((WindowManager)paramContext.getSystemService("window")).getDefaultDisplay();
          if (m > 0)
          {
            if (n <= 0)
              continue;
            a("w", m);
            a("h", n);
            return;
            localException1 = localException1;
            k = 0;
            m = k;
            n = 0;
            continue;
          }
          m = localDisplay.getWidth();
          continue;
          n = localDisplay.getHeight();
          continue;
        }
        catch (Exception localException2)
        {
          int k = m;
          continue;
        }
        int n = 0;
        int m = 0;
      }
    }
  }

  public String a()
  {
    return "/" + this.a + "/" + this.b + d.a(this.f);
  }

  public void a(Context paramContext)
  {
    a("app", Chartboost.sharedChartboost().getAppID());
    if (Build.PRODUCT.equals("sdk"))
    {
      a("model", "Android Simulator");
      a("identity", d.b());
    }
    while (true)
    {
      a("device_type", Build.MANUFACTURER + " " + Build.MODEL);
      a("os", "Android " + Build.VERSION.RELEASE);
      a("country", Locale.getDefault().getCountry());
      a("language", Locale.getDefault().getLanguage());
      a("sdk", "3.1.5");
      a("timestamp", new Date().getTime());
      b(paramContext);
      a("scale", paramContext.getResources().getDisplayMetrics().density);
      try
      {
        a("bundle", paramContext.getPackageManager().getPackageInfo(paramContext.getPackageName(), 128).versionName);
        return;
        a("model", Build.MODEL);
        a("identity", d.b());
      }
      catch (Exception localException)
      {
      }
    }
  }

  public void a(String paramString1, String paramString2)
  {
    if (this.e == null)
    {
      this.e = new JSONObject();
      this.c = "POST";
    }
    try
    {
      this.e.put(paramString1, paramString2);
      return;
    }
    catch (JSONException localJSONException)
    {
      localJSONException.printStackTrace();
    }
  }

  public String b()
  {
    return this.e.toString();
  }

  public void b(String paramString1, String paramString2)
  {
    if (this.d == null)
      this.d = new HashMap();
    this.d.put(paramString1, paramString2);
  }

  public Map<String, String> c()
  {
    return this.d;
  }

  public void c(String paramString1, String paramString2)
  {
    String str = b.b(b.a((this.c + " " + a() + "\n" + paramString2 + "\n" + b()).getBytes()));
    b("X-Chartboost-App", paramString1);
    b("X-Chartboost-Signature", str);
  }

  public JSONObject d()
  {
    try
    {
      JSONObject localJSONObject = new JSONObject();
      localJSONObject.put("controller", this.a);
      localJSONObject.put("action", this.b);
      localJSONObject.put("params", d.a(this.g));
      localJSONObject.put("query", d.b(this.f));
      localJSONObject.put("body", this.e);
      localJSONObject.put("ensureDelivery", this.i);
      localJSONObject.put("headers", d.b(this.d));
      return localJSONObject;
    }
    catch (Exception localException)
    {
      Log.w("Chartboost", "Unable to serialize failed request");
    }
    return null;
  }

  public static abstract interface a
  {
    public abstract void a(JSONObject paramJSONObject);
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.chartboost.sdk.impl.k
 * JD-Core Version:    0.6.2
 */